package controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import biz.IDepartmentBiz;
import entity.Department;

@Controller
public class DepartmentController {
	@Resource
	private IDepartmentBiz deptbiz;
	@RequestMapping("/selectAllDept")
	public String selectAllDept(HttpServletRequest request) {
		List<Department> deptlist = deptbiz.selectAllDepartment();
		request.setAttribute("deptlist", deptlist);
		return "EmployeeAdd.jsp";
	}
	@RequestMapping("/addDepartment")
	public String addDepartment(HttpServletRequest request) {
		String deptname = request.getParameter("deptname");
		String deptinfo = request.getParameter("deptinfo");
		Department dept = new Department();
		dept.setName(deptname);
		dept.setInfo(deptinfo);
		boolean flag = deptbiz.addDepartment(dept);
		return "redirect:/DeptAdd.jsp?flag=" + flag;
	}
	@RequestMapping("/selectConditionDepartment")
	public String selectConditionDepartment(HttpServletRequest request) {
		String curpage = request.getParameter("curpage");
		String deptname = request.getParameter("deptname");
		String deptinfo = request.getParameter("deptinfo");
		List<Department> deptlist = deptbiz.selectDepartment(deptname,deptinfo,Integer.parseInt(curpage));
		int pagesize = deptbiz.getPageSize(deptname,deptinfo);
		request.setAttribute("deptlist", deptlist);
		request.setAttribute("pagesize", pagesize);
		request.setAttribute("curpage", Integer.parseInt(curpage));
		return "DeptView.jsp";
	}
}
